<html>
	<head>
    	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    </head>
    <body>
    	<form action="sessionregner.php">
        	<input type="text" name="tal" /><br />
            <input type="submit" name="plus" value="+" />
            <input type="submit" name="minus" value="-" />
            <input type="submit" name="gange" value="*" />
            <input type="submit" name="dividere" value="/" />
      	</form>
            
    	<?php
			session_start();
			if(!isset($_REQUEST["tal"])){
				session_destroy();
				session_start();
			}
			if(isset($_SESSION["total"],$_REQUEST["tal"])){
				if(isset($_REQUEST["plus"])){
					$total = $_SESSION["total"] + $_REQUEST["tal"];
					$op = "+";
				}
				if(isset($_REQUEST["minus"])){
					$total = $_SESSION["total"] - $_REQUEST["tal"];
					$op = "-";
				}
				if(isset($_REQUEST["gange"])){
					$total = $_SESSION["total"] * $_REQUEST["tal"];
					$op = "*";
				}
				if(isset($_REQUEST["dividere"])){
					$total = $_SESSION["total"] / $_REQUEST["tal"];
					$op = "/";
				}
				$historikop = $_SESSION["historikop"];
				$historiktal = $_SESSION["historiktal"];
				array_push($historikop,$op);
				array_push($historiktal,$_REQUEST["tal"]);
				for($i=0;$i<count($historiktal);$i++){
					echo "$historikop[$i] $historiktal[$i]<br/>";
				}
				echo "resultat: $total";
			}
			else{
				$total = 0;
				$historiktal = array();
				$historikop = array();
			}
			$_SESSION["total"] = $total;
			$_SESSION["historiktal"] = $historiktal;
			$_SESSION["historikop"] = $historikop;
		?>
        <footer>&copy; Frederik Mattern</footer>
    </body>
</html>